#include "autosamplerprotocol.h"
#include "autosamplersendpacket.h"
#include "autosamplerparsepacket.h"
#include "autosamplerprotocoldata.h"
#include "autosamplerparsesystempacket.h"
#include "autosamplersendsystempacket.h"
#include "common/makepacket.h"
#include "common/findpacket.h"

namespace hplc
{
namespace qinfine
{

AutoSamplerProtocol::AutoSamplerProtocol(AutoSamplerParam &param, QObject *parent)
    : AutoSamplerProtocol (*new AutoSamplerProtocolData(), param, parent)
{

}

AutoSamplerProtocol::AutoSamplerProtocol(AutoSamplerProtocolData &data, AutoSamplerParam &param, QObject *parent)
    : ProtocolCommon (data, param, parent)
    , m_param(&param)
{
    AutoSamplerParsePacket *parser = new AutoSamplerParsePacket(data, param, this);
    AutoSamplerSendPacket *sender = new AutoSamplerSendPacket (data, this);
    connect(sender, &SendCommonPacket::requestSend, this, &ProtocolCommon::requestSend);

    AutoSamplerParseSystemPacket *systemParser = new AutoSamplerParseSystemPacket(data, param, this);
    AutoSamplerSendSystemPacket *systemSender = new AutoSamplerSendSystemPacket(data);

    data.m_parser = parser;
    data.m_sender = sender;
    data.m_systemParser = systemParser;
    data.m_systemSender = systemSender;
}

AutoSamplerProtocol::~AutoSamplerProtocol()
{
    AutoSamplerProtocolData *d = static_cast<AutoSamplerProtocolData*>(m_d);
    delete d->m_sender;
    delete d->m_parser;
    delete d->m_systemParser;
    delete d->m_systemSender;
}

AutoSamplerSendPacket *AutoSamplerProtocol::getAutoSamplerSender()
{
    return static_cast<AutoSamplerSendPacket*>(m_d->m_sender);
}

AutoSamplerSendSystemPacket *AutoSamplerProtocol::getAutoSamplerSystemSender()
{
    AutoSamplerProtocolData *m_d = static_cast<AutoSamplerProtocolData*>(this->m_d);
    return m_d->m_systemSender;
}

void AutoSamplerProtocol::setModel(quint8 model)
{
//    m_param->
}

} // qinfine
} // hplc
